<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <!-- 表单字段 -->
	<div class="layui-form-item">
        <label class="layui-form-label required">问题</label>
        <div class="layui-input-block">
            <input type="text" name="question" lay-verify="required" lay-reqtext="问题不能为空" placeholder="请输入问题" value="" class="layui-input">
            <tip>用户普遍关心的问题，将被添加到详情页的最下面</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">回答</label>
        <div class="layui-input-block">
            <input type="text" name="answer" lay-verify="required" lay-reqtext="回答不能为空" placeholder="请输入回答" value="" class="layui-input">
            <tip>针对此问题的官方回答</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" name="sortOrder" placeholder="请输入排序值" value="100" class="layui-input">
            <tip>问题摆放顺序，值越小越靠前</tip>
        </div>
    </div>
    <!-- <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男" checked="checked">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div> -->

    <!-- 确认保存按钮 -->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        // 监听提交
        form.on('submit(saveBtn)', function (data) {
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {

            //     // 关闭弹出层
            //     layer.close(index);

            //     var iframeIndex = parent.layer.getFrameIndex(window.name);
            //     parent.layer.close(iframeIndex);

            // });
			
            $.ajax({
                url: 'http://localhost:9000/api/shopgoodsissue/add',
                type: 'POST',
                data: JSON.stringify(data.field), // 将对象转换为JSON字符串传递
                dataType: 'JSON',
                headers: {
                    "Content-Type": "application/json" // 指定请求方式为JSON
                },
                success: function (res) {
                    if (res.code == '0') {
                        layer.msg("添加成功", {icon: 6});
                        parent.layui.table.reload('currentTable',{page:{curr:1}});
                        setTimeout(function(){
                            window.parent.layer.closeAll();
                                return false;
                        },1500);
                    } else {
                        layer.msg("添加失败", {icon: 5});
                        parent.layui.table.reload('currentTable',{page:{curr:1}});
                        setTimeout(function(){
                            window.parent.layer.closeAll();
                                return false;
                        },1500);
                    }
                },
                error: function (res) {
                    layer.msg('服务器开小差了', {
                        offset: '15px',
                        icon: 2,
                        time: 2000
                    });
                }
            });
        });
    });
</script>
</body>
</html>